//
//  MyInformationTableViewCell.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "MyInformationTableViewCell.h"

@implementation MyInformationTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
    }
    return self;
}




#pragma mark - 界面
- (void)layoutUI{

    [self addSubview:self.nextImageView];
    [self addSubview:self.myLabel];
    [self addSubview:self.firstLabel];
    [self addSubview:self.erWeiMaImageView];
    
    
    
    self.myLabel.sd_layout
    .leftSpaceToView(self,20 * [UIScreen zj_screenWScale])
    .topSpaceToView(self,15 * [UIScreen zj_screenHScale])
    .widthIs(80 * [UIScreen zj_screenWScale])
    .heightIs(20 * [UIScreen zj_screenHScale]);
    
    self.firstLabel.sd_layout
    .topSpaceToView(self,15 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.myLabel,15 * [UIScreen zj_screenWScale])
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale]);
    
    self.nextImageView.sd_layout
    .topSpaceToView(self,15 * [UIScreen zj_screenHScale])
    .rightSpaceToView(self,15 * [UIScreen zj_screenWScale])
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(15 * [UIScreen zj_screenWScale]);
    
    self.erWeiMaImageView.sd_layout
    .topSpaceToView(self,10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.myLabel,15 * [UIScreen zj_screenWScale])
    .heightIs(30 * [UIScreen zj_screenHScale])
    .widthIs(30 * [UIScreen zj_screenHScale]);
    
    
    UIView *under = [UIView new];
    under.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:under];
    under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1.5);
    
    self.backView = [UIView new];
    self.backView.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:self.backView];
    self.backView.sd_layout
    .leftEqualToView(self)
    .widthIs([UIScreen zj_screenWith])
    .heightIs(5 * [UIScreen zj_screenHScale])
    .bottomEqualToView(self);
    self.backView.hidden = YES;
}


#pragma mark - 私有方法

- (void)setModel:(MyInforNormalModel *)model{
    _model = model;
    self.myLabel.text = model.title;
    if (model.content.length == 0 ) {
        self.firstLabel.hidden = YES;
        self.erWeiMaImageView.image = [UIImage imageNamed:model.erImage];
    }else{
        self.erWeiMaImageView.hidden = YES;
        if ([self.myLabel.text isEqualToString:@"积分"]) {
            self.firstLabel.text = [NSString stringWithFormat:@"%@ 分",model.content];
        }else if ([self.myLabel.text isEqualToString:@"党员等级"]){
            self.firstLabel.text = [NSString stringWithFormat:@"%@ 级",model.content];
        }else if ([self.myLabel.text isEqualToString:@"勋章"]){
            NSInteger row = [model.content integerValue];
            for (int i = 0; i < row; i ++) {
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110 * [UIScreen zj_screenWScale] + 20 * [UIScreen zj_screenWScale] * i, 15 * [UIScreen zj_screenHScale], 20 * [UIScreen zj_screenWScale], 20 * [UIScreen zj_screenHScale])];
                label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
                label.text = @"🎖";
                [self addSubview:label];
            }
        }else{
            
            self.firstLabel.text = model.content;
        }
        
    }

}

- (void)setRow:(NSInteger)row{
    _row = row;
    if (row == 3 ) {
        self.backView.hidden = NO;
    }
}


#pragma mark - getter
- (UILabel *)myLabel{
    if (!_myLabel) {
        _myLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _myLabel;
}

- (UILabel *)firstLabel{
    if (!_firstLabel) {
        _firstLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _firstLabel;
}



- (UIImageView *)nextImageView{
    if (!_nextImageView) {
        _nextImageView = [UIImageView new];
        _nextImageView.contentMode = UIViewContentModeRight;
        _nextImageView.image = [UIImage imageNamed:@"mine_list_pop"];
    }
    return _nextImageView;
    
}


- (UIImageView *)erWeiMaImageView
{
    if (!_erWeiMaImageView) {
        _erWeiMaImageView = [UIImageView new];
        _erWeiMaImageView.contentMode = UIViewContentModeCenter;
    }
    return _erWeiMaImageView;


}


@end
